<template>
    <div>
        <input type="search" name="" id="" v-model="city" placeholder="请输入城市名称" @change="getData()">
    </div>
</template>

<script>
    import axios from 'axios';
    import { api_city, key} from '../common/constrant'
    import { mapActions } from 'vuex'
    export default{
        data(){
            return{
                "city":"",
            }
        },

        methods:{
            ...mapActions([
                "updateLocationAction"
            ]),
            getData(){
                axios.get(api_city,{
                    params:{
                        key:key,
                        location:this.city
                    }
                }).then((res) => {
                    // console.log(this.$store.state.location)
                    this.$store.commit('updateLocationMutations', res.data.location[0])
                    // console.log(this.$store.state.location)
                })
            }
        },

        // mounted(){
        //     this.getData();
        // }
    }
</script>

<style>

</style>